/*package com.utils.spring;

import java.util.Arrays;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.kyhd.lib.util.AESUtils;
import com.kyhd.lib.util.Constants;
import com.kyhd.lib.util.CookieUtil;
import com.kyhd.mogen.controller.model.LoginRequest;
import com.kyhd.mogen.dao.model.User;
import com.kyhd.mogen.service.UserService;
import com.kyhd.mogen.util.Constant;
import com.kyhd.mogen.util.EncryptUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

@Api("用户管理接口")
@RestController
@Slf4j
@RequestMapping(value = "/mogen/user", produces = {"application/json" })
public class MogenUserController {

	@Autowired
	UserService userService;
	@Value("${domain}")
	String domain;
	
	@ApiOperation(value="用户登陆", notes="")
	@RequestMapping(method={RequestMethod.POST},path="/login")
	public @ResponseBody ResponseEntity<String> login(HttpServletResponse response, @RequestBody LoginRequest loginRequest) {
		log.info("user login resquest:{}",loginRequest);
		HttpHeaders headers = new HttpHeaders();
		headers.put(HttpHeaders.CONTENT_TYPE, Arrays.asList("application/json;charset=UTF-8"));
		JSONObject ret = new JSONObject();

		String name = loginRequest.getName().trim();
		String pwd = loginRequest.getPwd().trim();
		pwd = EncryptUtil.encrypt(pwd);
		if(name!=null&&pwd!=null&&!"".equals(name)&&!"".equals(pwd)) {
			User user = this.userService.login(name,pwd);
			if(user!=null) {
				// 设置客户端 cookie
				CookieUtil.addCookie(response, Constants.USER_LOGIN, user.getId()+"", 60*60, domain,"/");
	        	String _info = user.getNick()+"#@#"+user.getOperateType()+"#@#";
	        	log.info("info:"+_info);
	        	CookieUtil.addCookie(response,Constants.USER_INFO,AESUtils.AESEncode(_info),60*60,domain,"/");
				
	        	ret.put("userId", user.getId());
	        	ret.put("nick", user.getNick());
				ret.put("type", user.getOperateType());
				ret.put("status", Constant.API_STATUS_SUCCESS);
				ret.put("message", "登陆成功");
			}else {
				ret.put("status", Constant.API_STATUS_FAILED);
				ret.put("message", "用户名或密码错误");
			}
		}else {
			ret.put("status", Constant.API_STATUS_FAILED);
			ret.put("message", "请填写用户名或密码");
		}
		
		log.info("user login response:{}",ret.toJSONString());
		return new ResponseEntity<String>(ret.toJSONString(), headers, HttpStatus.OK);
	}
	
}
*/